package com.example.zhugenew.adapter;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.mymvplibrary.adapter.BaseAdapter;
import com.example.mymvplibrary.adapter.BaseViewHolder;
import com.example.zhugenew.R;
import com.example.zhugenew.bean.RecommendBean;

import java.util.List;

public class RecommendAdapter extends BaseAdapter<RecommendBean.ListBean> {
    public ItemListener itemListener;

    public void setItemListener(ItemListener itemListener) {
        this.itemListener = itemListener;
    }


    public RecommendAdapter(List<RecommendBean.ListBean> datas, Context context, int layoutId) {
        super(datas, context, layoutId);
    }

    @Override
    public void bindData(BaseViewHolder holder, RecommendBean.ListBean listBean, int pos) {
        TextView text1 = holder.getView(R.id.tv_recommended_1);
        TextView text21 = holder.getView(R.id.tv_recommended_21);
        TextView text22 = holder.getView(R.id.tv_recommended_22);
        TextView text23 = holder.getView(R.id.tv_recommended_23);
        ImageView small = holder.getView(R.id.iv_recommended_small);
        ImageView big = holder.getView(R.id.iv_recommended_big);

        text1.setText(listBean.getTitle());
        if (listBean.getNews_label().equals("3")) {
            text21.setText("置顶");
            text21.setPadding(5, 5, 5, 5);
        }
        text22.setText(listBean.getSource_info().getSource_name());


        if (listBean.getThumb().size() != 0) {
            Glide.with(context).load(listBean.getThumb().get(0)).into(big);
        } else {
            Glide.with(context).load(listBean.getThumb()).into(big);
            text1.setWidth(2200);
        }
        Glide.with(context).load(listBean.getSource_info().getSource_img()).into(small);

        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                itemListener.onItemClickListener(pos);
            }
        });
    }
    public interface ItemListener {
        void onItemClickListener(int pos);
    }
}
 